//////////////////////////////////////////ok
#include"stdafx.h"
#include "bochs.h"


void IA32_CPU::BOUND_GwMa(Ia32_Instruction_c *i)
{
  if (i->modC0()) 
  {
    UndefinedOpcode(i);
  }

  Bit16s bound_min, bound_max;
  Bit16s op1_16 = IA32_READ_16BIT_REG(i->nnn());

  read_virtual_word(i->seg(), IA32_RMAddr(i),   (Bit16u *) &bound_min);
  read_virtual_word(i->seg(), IA32_RMAddr(i)+2, (Bit16u *) &bound_max);

  if (op1_16 < bound_min || op1_16 > bound_max) 
  {
    exception(IA32_BR_EXCEPTION, 0, 0);
  }

}

void IA32_CPU::BOUND_GdMa(Ia32_Instruction_c *i)
{
  if (i->modC0()) 
  {
    UndefinedOpcode(i);
  }

  Bit32s bound_min, bound_max;
  Bit32s op1_32 = IA32_READ_32BIT_REG(i->nnn());

  read_virtual_dword(i->seg(), IA32_RMAddr(i),   (Bit32u *) &bound_min);
  read_virtual_dword(i->seg(), IA32_RMAddr(i)+4, (Bit32u *) &bound_max);

  if (op1_32 < bound_min || op1_32 > bound_max) 
  {
    exception(IA32_BR_EXCEPTION, 0, 0);
  }

}

void IA32_CPU::INT1(Ia32_Instruction_c *i)
{
  interrupt(1, 1, 0, 0);
}

void IA32_CPU::INT3(Ia32_Instruction_c *i)
{
  exception(IA32_BP_EXCEPTION, 0, 0);
  //interrupt(3, 1, 0, 0);
}


void IA32_CPU::INT_Ib(Ia32_Instruction_c *i)
{

  Bit8u vector = i->Ib();
  interrupt(vector, 1, 0, 0);
}

void IA32_CPU::INTO(Ia32_Instruction_c *i)
{
  if (get_OF()) 
  {
    interrupt(4, 1, 0, 0);
  }
}
